package cn.edu.zafu.bigdata.zqt.studentsystem.cli;

import cn.edu.zafu.bigdata.zqt.studentsystem.constant.FileConst;
import cn.edu.zafu.bigdata.zqt.studentsystem.entity.Student;
import cn.edu.zafu.bigdata.zqt.studentsystem.service.AbstractService;
import cn.hutool.core.text.csv.CsvUtil;
import cn.hutool.core.text.csv.CsvWriter;
import cn.hutool.json.JSONUtil;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
 * @author zqt
 */
public class StudentManagerSystem {

    /**
     * 学生信息表
     */
    public static List<Student> studentList = JSONUtil
            .readJSONArray(new File(FileConst.FILE_PATH), StandardCharsets.UTF_8)
            .toList(Student.class);

    /**
     * 全局统一输入
     */
    public static Scanner scanner = new Scanner(System.in);

    /**
     * 全局统一输出
     */
    public static CsvWriter writer = CsvUtil.getWriter(FileConst.FILE_PATH, StandardCharsets.UTF_8);

    public static void main(String[] args) {
        String option;
        do {
            Menu.showMenu();
            option = scanner.nextLine().trim();
            AbstractService service = Menu.selectMenu(option);
            service.execute();
        } while (!"5".equals(option));
    }

}
